package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.ymatou.iapi.godmch.parameter.batchGetInviteCodesBean;
import com.ymatou.iapi.godmch.service.batchGetInviteCodesCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.godmch.buyer_invite_code;
import com.ymttest.database.model.godmch.buyer_invite_codeExample;
import com.ymttest.database.sqlwapper.godmch.buyer_invite_codeWapper;
/**
*批量获取买家端邀请码
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_batchGetInviteCodes{
	private static batchGetInviteCodesBean bean;
	private static batchGetInviteCodesCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量获取买家端邀请码");
	}

	@Before
	public void caseUp() {
		bean=new batchGetInviteCodesBean();
		call=new batchGetInviteCodesCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_batchGetInviteCodes_001() {
		Logger.start(true,"批量获取买家端邀请码");
		try {
	
			bean.setUserIdList(Lists.newArrayList(500011795,500011975));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatus1(), "验证status");
			buyer_invite_codeExample example=new buyer_invite_codeExample();
			example.createCriteria().andUserIdIn(bean.getUserIdList());
			buyer_invite_codeWapper codeMapper=new buyer_invite_codeWapper();
			List<buyer_invite_code> codes=codeMapper.selectByExample(example);	
			JsonArray return_codes=call.getCodes();
			for(int i=0;i<codes.size();i++){
				Logger.verifyEquals(return_codes.get(i).getAsJsonObject().get("userId").getAsInt(), codes.get(i).getUserId(), "验证userId");
				Logger.verifyEquals(return_codes.get(i).getAsJsonObject().get("inviteCode").getAsString(), codes.get(i).getInviteCode(), "验证inviteCode");
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_batchGetInviteCodes_002() {
		Logger.start(true,"批量获取买家端邀请码");
		try {
	
			bean.setUserIdList(Lists.newArrayList(500011795,9678676));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatus1(), "验证status");
			buyer_invite_codeExample example=new buyer_invite_codeExample();
			example.createCriteria().andUserIdIn(bean.getUserIdList());
			buyer_invite_codeWapper codeMapper=new buyer_invite_codeWapper();
			List<buyer_invite_code> codes=codeMapper.selectByExample(example);	
			JsonArray return_codes=call.getCodes();
			for(int i=0;i<codes.size();i++){
				Logger.verifyEquals(return_codes.get(i).getAsJsonObject().get("userId").getAsInt(), codes.get(i).getUserId(), "验证userId");
				Logger.verifyEquals(return_codes.get(i).getAsJsonObject().get("inviteCode").getAsString(), codes.get(i).getInviteCode(), "验证inviteCode");
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}